package com.sunflower.common.mybatis.core.service.impl;

import com.sunflower.common.core.constant.CacheConstants;
import com.sunflower.common.core.constant.CacheNames;
import com.sunflower.common.mybatis.core.mapper.BaseMapperPlus;
import com.sunflower.common.mybatis.core.service.ICacheService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author: SunLuQuan
 * @Date: 2024年03月25日 16:12
 * @Description: CacheServiceImpl
 * TODO
 */
@CacheConfig(cacheNames = CacheNames.DEFAULT_CACHE, cacheResolver = CacheConstants.CUSTOM_CACHE_RESOLVER, keyGenerator = CacheConstants.CACHE_KEY_GENERATOR)
public class CacheServiceImpl<T, M extends BaseMapperPlus<T, V>, V, B> extends BoServiceImpl<T, M, V, B> implements ICacheService {

    /**
     * 清除缓存
     */
    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public void clearAllCaches() {

    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean insertBatch(Collection<T> entityList) {
        return super.insertBatch(entityList);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean insertOrUpdateBatch(Collection<T> entityList) {
        return super.insertOrUpdateBatch(entityList);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean deleteById(Serializable id) {
        return super.deleteById(id);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean deleteById(Serializable id, boolean useFill) {
        return super.deleteById(id, useFill);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean deleteById(T entity) {
        return super.deleteById(entity);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean deleteByIds(Collection<?> list) {
        return super.deleteByIds(list);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean updateBatchById(Collection<T> entityList) {
        return super.updateBatchById(entityList);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public Boolean insertByBo(B bo) {
        return super.insertByBo(bo);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public Boolean updateByBo(B bo) {
        return super.updateByBo(bo);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public Boolean deleteWithValidByIds(Collection<Serializable> ids) {
        return super.deleteWithValidByIds(ids);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean insert(T entity) {
        return super.insert(entity);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean updateById(T entity) {
        return super.updateById(entity);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean insertBatch(Collection<T> entityList, int batchSize) {
        return super.insertBatch(entityList, batchSize);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean insertOrUpdateBatch(Collection<T> entityList, int batchSize) {
        return super.insertOrUpdateBatch(entityList, batchSize);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean updateBatchById(Collection<T> entityList, int batchSize) {
        return super.updateBatchById(entityList, batchSize);
    }

    @CacheEvict(keyGenerator = CacheConstants.EVICT_KEY_GENERATOR)
    @Override
    public boolean insertOrUpdate(T entity) {
        return super.insertOrUpdate(entity);
    }
}
